package com.htu.tax.controller;


import com.htu.tax.common.ResponseHelper;
import com.htu.tax.common.ResponseModel;
import com.htu.tax.payload.request.Address.AddAddressRequest;
import com.htu.tax.payload.request.Address.GetAddressRequest;
import com.htu.tax.payload.request.Address.UpdateAddressRequest;
import com.htu.tax.service.ITAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


@Service
@RestController
@CrossOrigin
@Api(tags = "邮寄地址接口")
@RequestMapping("/mailaddress")
public class TAddressController {
    @Resource
    private ITAddressService addressService;

    @CrossOrigin
    @ResponseBody
    @ApiOperation("邮寄地址添加")
    @PostMapping("/addAddress")
    public ResponseModel addAddress(@RequestBody AddAddressRequest request) {
        addressService.addAddress(request);
        return ResponseHelper.buildResponseModel("恭喜你，添加成功");
    }

    @CrossOrigin
    @ResponseBody
    @ApiOperation("查询邮寄地址列表")
    @PostMapping("/getAddress")
    public ResponseModel getAddress(@RequestBody GetAddressRequest request) {
        return ResponseHelper.buildResponseModel(addressService.getAddress(request));
    }

    @ApiOperation("修改邮寄地址")
    @CrossOrigin
    @PostMapping("/updateAddress")
    public ResponseModel updateAddress(@Valid @RequestBody UpdateAddressRequest request) {
        addressService.updateAddress(request);
        return ResponseHelper.buildResponseModel("恭喜你，修改成功");
    }

}
